fix: guard None refusal in ItemHelpers.extract_last_content#3427
Closed
ioleksiuk wants to merge 1 commit into
Closed
fix: guard None refusal in ItemHelpers.extract_last_content#3427ioleksiuk wants to merge 1 commit into
ioleksiuk wants to merge 1 commit into
Conversation
Follow-up to openai#3394 (just merged) that fixed the text branch of `extract_last_content` against `None` from `model_construct` / provider gateway paths. The refusal branch has the same `-> str` return type contract and the same Pydantic-typed `str` source field, so it can violate the contract in the same way: >>> from openai.types.responses import ( ... ResponseOutputMessage, ResponseOutputRefusal, ... ) >>> from agents.items import ItemHelpers >>> refusal_part = ResponseOutputRefusal.model_construct( ... refusal=None, type="refusal") >>> msg = ResponseOutputMessage.model_construct( ... id="m", role="assistant", status="completed", ... type="message", content=[refusal_part]) >>> ItemHelpers.extract_last_content(msg) None # but the function is typed `-> str` Apply the same `or ""` coercion and rationale comment that the text branch now has (items.py:687-691). Note: `extract_last_text` (declared `-> str | None`) is intentionally left alone — same reasoning as in openai#3394's final scope.
Member
|
@ioleksiuk Can you share the actual examples of this issue? I am unsure if this is a real issue. |
Contributor
Author
|
@seratch Thank you for reviewing the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #3394 (just merged) that fixed the text branch of `extract_last_content` against `None` from `model_construct` / provider gateway paths.
The refusal branch at `src/agents/items.py:693-694` has the same `-> str` return type contract and the same Pydantic-typed `str` source field (`ResponseOutputRefusal.refusal`), so it can violate the contract in the same way:
```python
Apply the same `or ""` coercion and rationale comment that the text branch now has (items.py:687-691).
Scope (apologies for the noise on #3394)
Same scope as the merged version of #3394 — only the `-> str` branches get the coercion. `extract_last_text` (declared `-> str | None`) is intentionally left alone because:
This PR is the equivalent fix on the refusal branch that I missed in #3394's first scope.
Test plan
Issue number
N/A — direct follow-up to merged #3394.
Checks